package practite.sort;

import java.util.Arrays;
import java.util.Random;

//冒泡排序

public class BubbleSort {
    public static void main(String[] args) {
        int[] array = getRandomArray();
//        System.out.println(Arrays.toString(array));
        int max = 0;
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array.length-i-1; j++) {
                if (array[j]>array[j+1]){
                    max = array[j];
                    array[j] = array[j+1];
                    array[j+1] = max;
//                    System.out.println(Arrays.toString(array));
                }else {
//                    System.out.println(Arrays.toString(array)+"111111");
                }
            }
//            System.out.println();
        }
        System.out.println(Arrays.toString(array));


    }


    //生成10位随机数组
    public static int[] getRandomArray(){
        int[] a = new int[10];
        for (int i = 0; i < a.length; i++) {
            a[i] = getRandom();
        }
        return a;
    }


    //随机数
    public static int getRandom(){
        Random random = new Random();
        int a = random.nextInt(100)+1;

        return a;
    }
}
